package com.carpedil.proxy.dao.impl;

import com.carpedil.proxy.dao.IUserDao;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/** @author Administrator */
public class UserDaoJdkProxy {
  UserDaoImpl userDao = new UserDaoImpl();

  public IUserDao getProxyInstance() {
    return (IUserDao)
        Proxy.newProxyInstance(
            UserDaoJdkProxy.class.getClassLoader(),
            userDao.getClass().getInterfaces(),
            new InvocationHandler() {
              @Override
              public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                System.out.println("jdk动态代理开始");
                method.invoke(userDao, args);
                System.out.println("jdk动态代理开始");
                return null;
              }
            });
  }
}
